//
//  PartyServiceCenterHeaderView.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/6/14.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "PartyServiceCenterHeaderView.h"

/**  默认高度370  */

@interface PartyServiceCenterHeaderView ()
/**  backImage  */
@property (strong, nonatomic) UIImageView  *backImageView;

/**  标题  */
@property (strong, nonatomic) UILabel  *headLine;
/**  数量  */
@property (strong, nonatomic) UILabel  *number;
/**  书记  */
@property (strong, nonatomic) UILabel  *shuji;
/**  委员  */
@property (strong, nonatomic) UILabel  *weiyuan;
/**  电话  */
@property (strong, nonatomic) UILabel  *phone;
/**  电话图片  */
@property (strong, nonatomic) UIImageView  *phoneImageView;
/**  地址图片  */
@property (strong, nonatomic) UIImageView  *addressImageView;
/**  地址  */
@property (strong, nonatomic) UILabel  *address;
/**  简介  */
@property (strong, nonatomic) UILabel  *jianjie;
/**  内容  */
@property (strong, nonatomic) UILabel  *content;
/**  中心线  */
@property (strong, nonatomic) UIView  *centerView;
/**  预约button  */
@property (strong, nonatomic) UIButton  *yuyueButton;


@end
@implementation PartyServiceCenterHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.backImageView];
        [self.backImageView addSubview:self.headLine];
//        [self addSubview:self.number];
//        [self addSubview:self.shuji];
//        [self addSubview:self.weiyuan];
        [self addSubview:self.phoneImageView];
        [self addSubview:self.phone];
        [self addSubview:self.addressImageView];
        [self addSubview:self.address];
        [self addSubview:self.yuyueButton];
//        [self addSubview:self.centerView];
//        [self addSubview:self.jianjie];
//        [self addSubview:self.content];
        
        self.backImageView.sd_layout
        .leftEqualToView(self)
        .topEqualToView(self)
        .widthIs([UIScreen zj_screenWith] )
        .heightIs(180 * [UIScreen zj_screenHScale]);

        
        self.headLine.sd_layout
        .leftEqualToView(self.backImageView)
        .bottomEqualToView(self.backImageView)
        .widthIs([UIScreen zj_screenWith])
        .heightIs(30 * [UIScreen zj_screenHScale]);
        
//        self.number.sd_layout
//        .topSpaceToView(self.backImageView, 20 * [UIScreen zj_screenHScale])
//        .leftSpaceToView(self, 20 * [UIScreen zj_screenWScale])        .heightIs(15 * [UIScreen zj_screenHScale])
//        .widthIs([UIScreen zj_screenWith] - 30 * [UIScreen zj_screenWScale]);
//        
//        self.shuji.sd_layout
//        .topSpaceToView(self.number, 15 * [UIScreen zj_screenHScale])
//        .leftEqualToView(self.number)
//        .heightIs(15 * [UIScreen zj_screenHScale])
//        .widthIs([UIScreen zj_screenWith] - 30 * [UIScreen zj_screenWScale]);
//
//        self.weiyuan.sd_layout
//        .topSpaceToView(self.shuji, 15 * [UIScreen zj_screenHScale])
//        .leftEqualToView(self.number)
//        .heightIs(15 * [UIScreen zj_screenHScale])
//        .widthIs([UIScreen zj_screenWith] - 30 * [UIScreen zj_screenWScale]);

        self.phoneImageView.sd_layout
        .topSpaceToView(self.backImageView, 10 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 20 * [UIScreen zj_screenWScale])
        .heightIs(20 * [UIScreen zj_screenHScale])
        .widthIs(20 * [UIScreen zj_screenHScale]);
        
        self.phone.sd_layout
        .topEqualToView(self.phoneImageView)
        .leftSpaceToView(self.phoneImageView, 10 * [UIScreen zj_screenWScale])
        .heightIs(20 * [UIScreen zj_screenWScale])
        .widthIs([UIScreen zj_screenWith] - 80 * [UIScreen zj_screenWScale]);
        

        self.addressImageView.sd_layout
        .topSpaceToView(self.phoneImageView, 10 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 20 * [UIScreen zj_screenWScale])
        .heightIs(20 * [UIScreen zj_screenHScale])
        .widthIs(20 * [UIScreen zj_screenHScale]);
        
        self.address.sd_layout
        .topEqualToView(self.addressImageView)
        .leftSpaceToView(self.addressImageView, 10 * [UIScreen zj_screenWScale])
        .heightIs(20 * [UIScreen zj_screenWScale])
        .widthIs([UIScreen zj_screenWith] - 80 * [UIScreen zj_screenWScale]);

        
        self.yuyueButton.sd_layout
        .bottomSpaceToView(self.address, -10 * [UIScreen zj_screenHScale])
        .rightSpaceToView(self, 15 * [UIScreen zj_screenWScale])
        .heightIs(30 * [UIScreen zj_screenHScale])
        .widthIs(60 * [UIScreen zj_screenWScale]);
        

        
        self.centerView.sd_layout.topSpaceToView(self, 130 * [UIScreen zj_screenHScale])
        .leftEqualToView(self)
        .rightEqualToView(self)
        .heightIs(1);
        
//        self.jianjie.sd_layout
//        .topSpaceToView(self.centerView, 18 * [UIScreen zj_screenHScale])
//        .leftEqualToView(self.headLine)
//        .heightIs(14 * [UIScreen zj_screenHScale])
//        .widthIs(90);
        }
    return self;
}

- (void)setModel:(PartyServiceCenterHeaderModel *)model{
    _model = model;
    [self.backImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,model.ORGCONCENTER_IMGPATHS]] placeholderImage:PlaceholderBIGImage];

    self.headLine.text = [NSString stringWithFormat:@"    %@",model.DEPT_NAME];
    self.shuji.text = [NSString stringWithFormat:@"书记: %@",model.DEPTSECRETARY_NAME];
    self.weiyuan.text = [NSString stringWithFormat:@"委员: %@",model.DEPTCONTACTS_NAME];
    if (model.DEPTCONTACTS_MOBILE.length == 0) {
        self.phone.text = @"暂无";
    }else{
        self.phone.text = model.DEPTCONTACTS_MOBILE;
    }
    
//    if (model.DEPT_DEADDRESS.length == 0) {
//        self.address.text = @"暂无";
//    }else{
//        self.address.text = model.DEPT_DEADDRESS;
//    }
    
    NSString *address;
    if (model.DEPT_DEADDRESS.length == 0) {
        address = @"暂无";
    }else{
        address = model.DEPT_DEADDRESS;
    }
    
    CGFloat height = [CalculateLabelHeight CalculateLabelHeightWithString:address font:16 * [UIScreen zj_textFontScale] width:[UIScreen zj_screenWith] - 80 * [UIScreen zj_screenWScale]].height;
    self.address.text = address;
    if ( height > 20 * [UIScreen zj_screenHScale]) {
        self.address.sd_layout.heightIs(height + 1);
        [self.address updateLayout];
    }

}

- (void)setSchoolModel:(ZJCommunitySchoolModel *)schoolModel{
    _schoolModel = schoolModel;
    [self.backImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,schoolModel.IMGURL]] placeholderImage:PlaceholderBIGImage];
    self.headLine.text = [NSString stringWithFormat:@"    %@",schoolModel.NAME];          
    self.phone.text = [NSString string:schoolModel.PHONE isNilStringReturnDeftString:@"暂无"];
    self.address.text = [NSString string:schoolModel.ADDRESS isNilStringReturnDeftString:@"暂无"];
    self.yuyueButton.hidden = NO;
}




- (void)clickButton{
    if (self.delegate) {
        [self.delegate PartyServiceCenterHeaderClickYuYue_button];
    }
}

#pragma mark - getter

- (UIImageView *)backImageView{
    if (!_backImageView) {
        _backImageView = [UIImageView new];
        _backImageView.contentMode = UIViewContentModeScaleAspectFill;
        _backImageView.clipsToBounds = YES;
    }
    return _backImageView;
}
- (UILabel *)headLine{
    if (!_headLine) {
        _headLine = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor whiteColor];
            label.backgroundColor = [UIColor zj_colorWithR:20 G:20 B:20 Al:0.4];
            label.font = LYPBOLDFONT(16);
            label;
        });
    }
    return _headLine;
}

- (UILabel *)number{
    if (!_number) {
        _number = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(16);
            label;
        });
    }
    return _number;
}


- (UILabel *)phone{
    if (!_phone) {
        _phone = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(16);
            label;
        });
    }
    return _phone;
}


- (UILabel *)weiyuan{
    if (!_weiyuan) {
        _weiyuan = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(16);
            label;
        });
    }
    return _weiyuan;
}


- (UILabel *)shuji{
    if (!_shuji) {
        _shuji = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(16);
            label;
        });
    }
    return _shuji;
}

- (UILabel *)address{
    if (!_address) {
        _address = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(16);
            label.numberOfLines = 0;
            label;
        });
    }
    return _address;
}

- (UILabel *)content{
    if (!_content) {
        _content = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textGrayColor];
            label.numberOfLines = 0;
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(16);
            label;
        });
    }
    return _content;
}


- (UILabel *)jianjie{
    if (!_jianjie) {
        _jianjie = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(17);
            label.text = @"简介:";
            label;
        });
    }
    return _jianjie;
}

- (UIImageView *)addressImageView{
    if (_addressImageView == nil) {
        _addressImageView = [UIImageView new];
        _addressImageView.contentMode = UIViewContentModeCenter;
        _addressImageView.image = [UIImage imageNamed:@"icon_addressB"];
    }
    return _addressImageView;
}

- (UIImageView *)phoneImageView{
    if (_phoneImageView == nil) {
        _phoneImageView = [UIImageView new];
        _phoneImageView.contentMode = UIViewContentModeCenter;
        _phoneImageView.image = [UIImage imageNamed:@"icon_telphoneB"];
    }
    return _phoneImageView;
}

- (UIView *)centerView{
    if (!_centerView) {
        _centerView = [UIView new];
        _centerView.backgroundColor = [UIColor lightGrayColor];
    }
    return _centerView;
}

- (UIButton *)yuyueButton{
    if (!_yuyueButton) {
        _yuyueButton = ({
            UIButton *button = [UIButton new];
            [button setTitle:@"预约" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.backgroundColor = [UIColor themeColor];
            [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
            button.layer.cornerRadius = 4;
            button.titleLabel.font = LYPFONT(16);
            button.layer.masksToBounds = YES;
            button.hidden = YES;
            button;
            
        });
    }
    return _yuyueButton;
}

@end
